package com.xiaoyu.linkedArray;

/**
 * @program: DS_and_A
 * @description: 删除链表中的结点
 *
 * 输入：head = [4,5,1,9], node = 5
 * 输出：[4,1,9]
 * 解释：给定你链表中值为5的第二个节点，那么在调用了你的函数之后，该链表应变为 4 -> 1 -> 9.
 *
 * @author: YuWenYi
 * @create: 2021-05-10 09:40
 **/
public class DeleteNode {

    public static void deleteNode(ListNode node) {
        node.val = node.next.val;
        node.next = node.next.next;
    }

    public static void main(String[] args) {
        ListNode link = new ListNode(1,new ListNode(2,
                new ListNode(3,new ListNode(4))));

        deleteNode(link.next.next);


        while (link.hasNext()){
            System.out.print(link.val+",");
            link = link.next;
        }
        System.out.print(link.val);
    }
}
